package me.zhengjie.modules.system.rest.front;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.system.bo.req.YplyReq;
import me.zhengjie.modules.system.bo.resp.QztyIndexResp;
import me.zhengjie.modules.system.repository.DccYaopinlanyongRepository;
import me.zhengjie.modules.system.service.DccArticleService;
import me.zhengjie.modules.system.service.DccIndexService;
import me.zhengjie.modules.system.service.DccYaopinlanyongService;
import me.zhengjie.modules.system.service.dto.DccArticleQueryCriteria;
import me.zhengjie.modules.system.service.dto.DccIndexDto;
import me.zhengjie.modules.system.service.dto.DccIndexQueryCriteria;
import me.zhengjie.modules.system.service.dto.DccYaopinlanyongQueryCriteria;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author cjl
 * @className FrontIndexController
 * @description: TODO
 * @company: 上海明我信息技术有限公司
 * @date 2023年05月18日
 * @version: 1.0
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "DCC首页相关管理")
@RequestMapping("/front/index")
public class FrontIndexController {
    private final DccYaopinlanyongService dccYaopinlanyongService;

    private final DccArticleService dccArticleService;

    private final DccIndexService dccIndexService;


    @Log("首页")
    @ApiOperation("首页")
    @AnonymousAccess
    @PostMapping(value = "/index")
    public ResponseEntity<QztyIndexResp> index(@RequestBody YplyReq yplyReq){
        DccYaopinlanyongQueryCriteria criteria =new DccYaopinlanyongQueryCriteria();
        QztyIndexResp qztyIndexResp=new QztyIndexResp();
        //药品滥用一览
        Sort sort =Sort.by(Sort.Direction.DESC,"updatedAt");
//        Pageable pageable =PageRequest.of(yplyReq.getPage()-1, yplyReq.getSize(),sort);
//        Map<String, Object> stringObjectMap = dccYaopinlanyongService.queryAll(criteria, pageable);
        DccArticleQueryCriteria criteriaW =new DccArticleQueryCriteria();
        //定义排序规则
        Sort sort1 =Sort.by(Sort.Direction.DESC,"updatedAt");
        Pageable pageable1 =PageRequest.of(yplyReq.getPage()-1, yplyReq.getSize(),sort1);
        Map<String, Object> stringObjectMapW = dccArticleService.queryAll(criteriaW, pageable1);
        DccIndexQueryCriteria criteria1=new DccIndexQueryCriteria();
        List<DccIndexDto> dccIndexDtos = dccIndexService.queryAll(criteria1);
        //相关资讯
        qztyIndexResp.setImgUrl(dccIndexDtos);
        qztyIndexResp.setXgzx(stringObjectMapW);
//        qztyIndexResp.setYply(stringObjectMap);
        qztyIndexResp.setXgzx(stringObjectMapW);

        return new ResponseEntity<>(qztyIndexResp, HttpStatus.OK);
    }


}
